//
//  HSMessageCell.swift
//  HomeSchoolDemo
//
//  Created by 张晓林 on 16/10/10.
//  Copyright © 2016年 张晓林. All rights reserved.
//

import UIKit

class HSMessageCell: UITableViewCell {
    @IBOutlet weak var messageIconV: UIImageView!
    @IBOutlet weak var messageUserNameL: UILabel!
    @IBOutlet weak var messageUserType: UILabel!
    @IBOutlet weak var messageDateL: UILabel!
    @IBOutlet weak var messageTitleL: UILabel!
    @IBOutlet weak var messageContentL: UILabel!
    @IBOutlet weak var messageLikeBtn: UIButton!
    @IBOutlet weak var messageReplayViewH: NSLayoutConstraint!
    
    // 回复背景视图(使用了自定义类型)
    @IBOutlet weak var messageReplayBgV: HSReplayView!
    
    // 数据模型(消息视图模型)
    var messageVM: HSMessageViewModel? {
        didSet {
            messageUserNameL.text = messageVM?.message.not_Name
            messageUserType.text = messageVM?.message.not_courseName
            messageDateL.text = messageVM?.message.not_createDate
            messageTitleL.text = messageVM?.message.not_title
            messageContentL.text = messageVM?.message.not_content
            // 设置点赞按钮
            let likeN = messageVM?.message.likenum ?? 0
            if likeN > 0 {
                messageLikeBtn.setTitle("\(likeN)", for: .selected)
                messageLikeBtn.isSelected = true
            }else {
                messageLikeBtn.isSelected = false
            }
            // 传递模型给回复视图
            messageReplayBgV.messageVM = messageVM
            // 设置高度
            messageReplayViewH.constant = messageVM?.replayViewH ?? 0
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // 设置圆角
        messageIconV.layer.cornerRadius = 25
        messageIconV.layer.masksToBounds = true
        
        // 设置用户类型视图边框
        messageUserType.layer.cornerRadius = 8
        messageUserType.layer.borderWidth = 1
        messageUserType.layer.borderColor = UIColor().colorWithHex(0x00a0e9).cgColor
    }

    // 点赞按钮监听事件回调
    @IBAction func messageLikeBtnClicked(_ sender: UIButton) {
        print("点赞")
    }
    
    // 回复按钮监听事件回调
    @IBAction func messageReplayBtnClicked(_ sender: AnyObject) {
        print("回复")
    }
    
}
